package cn.lg.soar.common.model;

import eu.bitwalker.useragentutils.DeviceType;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;

/**
 * 日志数据
 * @author luguoxiang
 * @date 2022/4/23
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Slf4j(topic = "operationLog")
@Getter
@Setter
public class LogDTO {

    @ApiModelProperty("租户id")
    private Integer tenantId;

    @ApiModelProperty("操作者（谁）")
    private Long userId;

    @ApiModelProperty("操作者ip（何地）")
    private String userIp;

    @ApiModelProperty("执行开始时间（何时）")
    private LocalDateTime datetime;

    @ApiModelProperty("操作（做了什么）")
    private String operate;

    @ApiModelProperty("哪个接口")
    private String path;

    @ApiModelProperty("终端类型")
    private DeviceType deviceType;

    @ApiModelProperty("用户系统")
    private String system;

    @ApiModelProperty("用户浏览器")
    private String browser;

    @ApiModelProperty("详情（数据）")
    private Object data;

    @ApiModelProperty("数据类型")
    private String dataType;

    @ApiModelProperty("数据id")
    private String dataId;

    @Override
    public String toString() {
        return String.format(
                "%s,%s,%s【%s】%s，%s【%s】%s，%s",
                tenantId, userId, userIp,
                operate,
                system, browser,
                data,
                dataType, dataId
        );
    }

    /**
     * 打印操作日志
     */
    public void print() {
        log.info("{}\t{}", datetime, toString());
    }

}
